#ifndef DHWL_SOCKET_SOCKETEPOLL_H
#define DHWL_SOCKET_SOCKETEPOLL_H

#include "global.h"
#include "Sock.h"

extern "C" {
    #include <sys/epoll.h>
}

#define LIMIT_CONNECT_NUMBER    20000
#define LIMIT_EVENT_NUMBER  2000
#define EPOLL_WAITTIME  -1

namespace ZY {

    class SocketEpoll
    {
        public:
            SocketEpoll();
            SocketEpoll( int event_number );
            virtual ~SocketEpoll();
            void setEventNumber( int event_number );
            int insert( Sock *sock , uint32_t control );
            int insert( Sock *sock ) {return this->insert( sock , EPOLLIN | EPOLLOUT );};
            int remove( Sock *sock );
            int update( Sock *sock , uint32_t control );
            int updateToIn( Sock *sock ){return this->update( sock , EPOLLIN ); sock->setStatus(3,true);sock->setStatus(4,false);};
            int updateToOut( Sock *sock ){return this->update( sock , EPOLLOUT ); sock->setStatus(3,false);sock->setStatus(4, true );};
            void startWait( void (*doFunc)( struct epoll_event *) , void(*eventDone)(void) ) {startWait(  LIMIT_EVENT_NUMBER , EPOLL_WAITTIME , doFunc , eventDone );};
            void startWait( void (*doFunc)( struct epoll_event *) , void(*eventDone)(void) , const int timeout ) {startWait(  LIMIT_EVENT_NUMBER , timeout , doFunc , eventDone );};
            void startWait( void (*doFunc)( struct epoll_event *) ) {startWait(  LIMIT_EVENT_NUMBER , -1 , doFunc , NULL );};
            void startWait( const int limit_events_number , const int timeout , void (*doFunc)( struct epoll_event *) , void(*eventDone)(void) );
            SocketEpoll *getPointer() {return this;};
        protected:
        private:
            int epoll_fd;
            void _create( int event_number );
    };

};
#endif // SOCKETEPOLL_H
